package com.guxingke.gblog.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.guxingke.gblog.service.impl.CategoryServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

public class ManageAction extends ActionSupport implements ServletRequestAware {
	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unused")
	private HttpServletRequest request;
	private HttpSession session;

	private String mainPage;

	@Override
	public String execute() throws Exception {
		if (!isPass()) {
			return ERROR;
		}
		session.setAttribute("categories",new CategoryServiceImpl().getCategories());
		setMainPage("template/manage/detail.jsp");
		return SUCCESS;
	}

	public String articleManage() throws Exception {
		if (!isPass()) {
			return ERROR;
		}
		return "articleManage";
	}

	public String categoryManage() throws Exception {
		if (!isPass()) {
			return ERROR;
		}
		return "categoryManage";
	}

	public String msgManage() throws Exception {
		if (!isPass()) {
			return ERROR;
		}
		return "msgManage";
	}

	public String pictureManage() throws Exception {
		if (!isPass()) {
			return ERROR;
		}
		return "pictureManage";
	}

	public String aboutManage() throws Exception {
		if (!isPass()) {
			return ERROR;
		}
		return "aboutManage";
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
		this.session = request.getSession();
	}

	public String getMainPage() {
		return mainPage;
	}

	public void setMainPage(String mainPage) {
		this.mainPage = mainPage;
	}

	private boolean isPass() {
		return session.getAttribute("admin") != null;
	}
}
